package com.gxsyh.nantie.user.management.provider.controller;

import com.gxsyh.nantie.commons.dto.ResponseResult;
import com.gxsyh.nantie.user.management.provider.controller.dto.PersionParam;
import com.gxsyh.nantie.user.management.provider.domain.TbRole;
import com.gxsyh.nantie.user.management.provider.domain.TbUser;
import com.gxsyh.nantie.user.management.provider.service.TbRoleService;
import com.gxsyh.nantie.user.management.provider.service.TbUserService;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @email yom535@outlook.com
 * @author: 刘锋嘉(Liu Fengjia)
 * @date: 2020/1/16
 * @time: 11:44
 * @Description:
 */
@RestController
public class PermissionController {
    @Resource
    TbRoleService tbRoleService;

    @Resource
    TbUserService tbUserService;

    /**
     *查询某个用户的角色
     */
    @GetMapping(value = "/user/get/one/user/role")
    public ResponseResult<PersionParam> getRole(@RequestParam Long userId){
        PersionParam persionParam=new PersionParam();
        List<TbRole> roleInfo = tbRoleService.getRoleInfo(userId);
        for (TbRole tbRole : roleInfo) {
            String enname = tbRole.getEnname().trim();
            if (enname.equals("diningManagement")){
                persionParam.setDiningManagement(true);
            }
            if (enname.equals("userManagement")){
                persionParam.setUserManagement(true);
            }
            if (enname.equals("permissionManagement")){
                persionParam.setPermissionManagement(true);
            }
            if (enname.equals("refundManagement")){
                persionParam.setRefundManagement(true);
            }
            if (enname.equals("superAdmin")){
                persionParam.setDiningManagement(true);
                persionParam.setUserManagement(true);
                persionParam.setPermissionManagement(true);
                persionParam.setRefundManagement(true);
            }
        }

        TbUser tbUser = tbUserService.selectOneUserById(userId);
        if (tbUser.getSubsidyStatus()==1){
            persionParam.setSubsidy(true);
        }

        return new ResponseResult<>(HttpStatus.OK.value(),"查询权限成功",persionParam);
    }
}
